﻿/**
 * 
 */
var xhr;
function checkName() {
	xhr = new XMLHttpRequest(); 
	var name = document.getElementById("name").value;
	var uri = "loginregister!checkName.action?name="
		+ name;
	uri = encodeURI(uri);
	xhr.open("post", uri, true);
	xhr.onreadystatechange = testName;
	xhr.send();
}
			
function testName() {
	//服务器端已经成功交互，并且成功返回数据的时候！
	if(xhr.readyState == 4 && xhr.status == 200 ) {
		var res = xhr.responseText;   //获取服务器端传回的数据。
		var resp = eval("("+res+")");
		var name_i = document.getElementById("name_i");
					
		if(resp) {
				name_i.innerHTML = "用户名可用";
				name_i1.innerHTML = "用户名可用";
				//alert("用户名可用");
		}else {
			name_i.innerHTML ="用户名不可用";
			name_i1.innerHTML = "用户名可用";
		}
	}
}

function checkPassword() {
	xhr = new XMLHttpRequest();
	var pwd = document.getElementById("pwd").value;
	var uri = "loginregister!checkPassword.action?pwd="+ pwd;
	xhr.open("post", uri, true);
	xhr.onreadystatechange = testPassword;
	xhr.send();
}

function testPassword() {
	//服务器端已经成功交互，并且成功返回数据的时候！
	if(xhr.readyState == 4 && xhr.status == 200 ) {
		var res = xhr.responseText;   //获取服务器端传回的数据。
		var resp = eval("("+res+")");
		var pwd_i = document.getElementById("pwd_i");
		if(resp) {
			pwd_i.innerHTML = "密码可用";
		}else {
			pwd_i.innerHTML ="密码不可用";
		}
	}
}

function checkPassword_() {
	xhr = new XMLHttpRequest();
	var pwd = document.getElementById("pwd").value;
	var pwd_ = document.getElementById("pwd_").value;
	//name_i.innerHTML = name;
	var uri = "loginregister!checkPassword_.action?pwd="+ pwd+"&pwd_="+ pwd_;
	xhr.open("post", uri, true);
	xhr.onreadystatechange = testPassword_;
	xhr.send();
}

function testPassword_() {
	//服务器端已经成功交互，并且成功返回数据的时候！
	if(xhr.readyState == 4 && xhr.status == 200 ) {
		var res = xhr.responseText;   //获取服务器端传回的数据。   
		var resp = eval("("+res+")");
		var rpwd_i = document.getElementById("rpwd_i");
					
		if(resp) {
			rpwd_i.innerHTML = "密码一致";
		}else {
			rpwd_i.innerHTML ="密码不一致，请重新输入";
		}
	}
}

function checkEmail () {
	xhr = new XMLHttpRequest();
	var email = document.getElementById("email").value;
	var uri = "loginregister!checkEmail.action?email="+email;
	xhr.open("post", uri, true);
	xhr.onreadystatechange = testEmail;
	xhr.send();
}

function testEmail() {
	//服务器端已经成功交互，并且成功返回数据的时候！
	if(xhr.readyState == 4 && xhr.status == 200 ) {
		var res = xhr.responseText;   //获取服务器端传回的数据。   
		var resp = eval("("+res+")");
		var email_i = document.getElementById("email_i");
					
		if(resp) {
			email_i.innerHTML = "邮箱可用";
		}else {
			email_i.innerHTML ="邮箱不可用";
		}
	}
}

function uploadImage () {
}

function changeCode() {
	document.login.code.src = "loginregister!checkCode.action?time="
			+ new Date();
}

function changeCode_() {
	document.register.code.src = "loginregister!checkCode.action?time="
			+ new Date();
}

function checkCode() {
	xhr = new XMLHttpRequest();
	var checkcode = document.getElementById("checkcode").value;
	checkcode_e.innerHTML = name;
	var uri = "loginregister!checkCheckCode.action?checkcode="
		+ checkcode;
	xhr.open("get", uri, true);
	xhr.onreadystatechange = testCode;
	xhr.send();
}
			
function testCode() {
	//服务器端已经成功交互，并且成功返回数据的时候！
	if(xhr.readyState == 4 && xhr.status == 200 ) {
		var res = xhr.responseText;   //获取服务器端传回的数据。   
		var resp = eval("("+res+")");
		var checkcode_e = document.getElementById("checkcode_e");
					
		if(resp) {
			checkcode_e.innerHTML = "不可用";
		}else {
			checkcode_e.innerHTML ="可用";
		}
	}
}

function register() {
	alert("注册");
}

function freset(obj)
{
	obj.reset();
}

function fregister()
{
	var uri="forum/jsp/register.jsp";
	//alert(uri);
	window.location.href=uri;
}